1 //+-----------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //------------------------------------------------------------------------
10 #include "precompiled.hxx"
11 #include "Detours.hxx"
12 #include "..\Detours\Detours.h"
14 // The managed PresentationHostSecurityManager needs to convince the ClickOnce elevation prompt to use the
15 // browser's top-level window as the owner. The prompt dialog is created without an explicit owner, on its
16 // own thread. As a fallback, SWF.Form.ShowDialog() uses the active window as owner. But there is no other
17 // window on the dialog's thread. So, we fake it by detouring ::GetActiveWindow() and returning the browser's
18 // top-level window on the first call.
19 HWND g_fakeActiveWindow
;
21 // DLL-exported. Called by PresentationHostSecurityManager.
22 void __stdcall
SetFakeActiveWindow(HWND hwnd
)
24 g_fakeActiveWindow
= hwnd
;
27 HWND (WINAPI
*Detours::s_pfGetActiveWindow
)() = &GetActiveWindow
;
29 HRESULT
Detours::Init()
33 CHECK_ERROR_CODE(DetourTransactionBegin());
34 CHECK_ERROR_CODE(DetourUpdateThread(GetCurrentThread()));
35 CHECK_ERROR_CODE(DetourAttach((void**)&s_pfGetActiveWindow
, GetActiveWindowDetour
));
36 CHECK_ERROR_CODE(DetourTransactionCommit());
42 void Detours::Uninit()
44 if(s_pfGetActiveWindow
!= GetActiveWindow
) // detoured?
46 if(DetourTransactionBegin() == NOERROR
&&
47 DetourUpdateThread(GetCurrentThread()) == NOERROR
&&
48 DetourDetach((void**)&s_pfGetActiveWindow
, GetActiveWindowDetour
) == NOERROR
)
50 DetourTransactionCommit();
59 HWND
Detours::GetActiveWindowDetour()
61 if(g_fakeActiveWindow
)
63 HWND hwnd
= g_fakeActiveWindow
;
64 g_fakeActiveWindow
= 0;
67 return (*s_pfGetActiveWindow
)(); // call the real function